from xbd.publics.public_cc import PublicCc
from xbd.publics.public_cqjy import PublicCqjy


class TransactionVote(PublicCc):
    '''其他事务表决'''
    # name = '测试其他事务'+PublicCqjy.now_str
    name = '测试其他事务0328101508'
    print(name)
    PublicCqjy = PublicCqjy()

    def test_01(self):
        '''发布表决'''
        url = '/api/core/v1/transactionVote/saveTransactionVote'
        data = {
            "creditCode": self.read_login('creditCode'),
            "voteUser": "000",
            "voteDay": 5,
            "voteType": 0,
            "organizationName": self.read_login('organizationName'),
            "organizationAddress": "地址123456789",
            "contactUserName": self.read_login('userName'),
            "contactPhone": self.read_login('account'),
            "transactionName": self.name,
            "htmlContent": "<p>正文124124324</p>",
            "transactionVoteSelectionList": [
                {
                    "remark": "说明123214",
                    "selectionName": "选项名234324"
                }
            ],
            "operate": 1
        }
        self.post(url, data, newtoken=1)

    def test_02(self):
        '''村名表决'''
        for phone in [15000000000]:
            self.PublicCqjy.phones = [(phone, 4)]
            # 获取表决事务id
            url1 = '/api/admin/v1/vote/getTransactionVoteProjectPage'
            data = {"status": 0, 'current': 1, "transactionName": self.name}
            res1 = self.PublicCqjy.post(url1, data, reget=1)[
                'data']['records'][0]
            # 获取表决详情
            url2 = '/api/admin/v1/vote/getTransactionVoteProjectDetail'
            data = {
                "transactionVoteProjectId": res1['transactionVoteProjectId']}
            res2 = self.PublicCqjy.post(url2, data, reget=1)[
                'data']['transactionVoteSelectionList'][0]
            # 表决
            url = '/api/admin/v1/vote/saveTransactionVoteRecord'
            data = {
                "transactionVoteProjectId": res1['transactionVoteProjectId'],
                "transactionVoteProjectSelectionId": res2['transactionVoteProjectSelectionId']}
            res = self.PublicCqjy.post(url, data, reget=1)

    def test_03(self):
        '''修改其他事务定时任务'''
        end_data = str(datetime.now() + timedelta(seconds=5))[:19]
        sql = f"UPDATE t_transaction_vote_project PublicCqjy join t_transaction_vote_project_timer_job b on PublicCqjy.transaction_vote_project_id=b.transaction_vote_project_id set b.end_date='{end_data}' WHERE PublicCqjy.transaction_name='{self.name}'"
        self.PublicCqjy.run_sql(sql)
